<%@ page import="java.net.URLDecoder" %><%--
  Created by IntelliJ IDEA.
  User: Ray
  Date: 2019/9/11
  Time: 18:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>登录</title>
    <link rel="stylesheet" href="${path}/plugins/bootstrap/css/bootstrap.css" type="text/css">
    <%--<link rel='stylesheet' href='${path}/css/nav.css' type='text/css'>--%>
</head>
<body>
<%--第一种解决方案 - 利用jsp的代码块来处理--%>
<%
    //获取cookie
    //每次请求的时候,会将所有的cookie全部发送给server
    Cookie[] cookies = request.getCookies();
    String uname="";
    String pwd="";
    //定义一个标记位
    boolean flag = false;
    if(null!=cookies && cookies.length>0){
        for(Cookie c:cookies){
            //找到name=username的cookie
            if("userLogin".equals(c.getName())){
                String value = c.getValue();

                if(value.trim().length()==0){
                    break;
                }
                // System.out.println(value.split(":")[0]);

                //如果对用户名进行二级编码,那么此处需要进行二级解码
                uname = value.split(":")[0];

                uname = URLDecoder.decode(URLDecoder.decode(uname,"utf-8"),"utf-8");

                pwd = value.split(":")[1];

                flag = true;
                break;
            }
        }
    }
    pageContext.setAttribute("uname",uname);
    pageContext.setAttribute("pwd",pwd);
    pageContext.setAttribute("flag",flag);
%>
<%@include file="../common/header.jsp"%>

<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel">请登录</h4>
        </div>
        <div class="modal-body">
            <!--表单登录-->
            <form class="form-horizontal" role="form" action="${path}/user/login" method="post">
                <div class="form-group has-feedback">
                    <label for="firstname" class="col-sm-4 control-label">用户名</label>
                    <div class="col-sm-4">
                        <input name='username' type="text" class="form-control" id="firstname" value="${uname}" placeholder="请输入用户名">
                        <span class="form-control-feedback glyphicon glyphicon-user"></span>
                    </div>
                    <c:if test="${param.error==0}">
                        <label  class="col-sm-3 control-label">用户不存在</label>
                    </c:if>
                </div>
                <div class="form-group has-feedback">
                    <label for="lastname" class="col-sm-4 control-label">密码</label>
                    <div class="col-sm-4">
                        <input name='password' value="${pwd}" type="password" class="form-control" id="lastname" placeholder="请输入密码">
                        <span class="form-control-feedback glyphicon glyphicon-lock"></span>
                    </div>
                    <c:if test="${param.error==1}">
                        <label  class="col-sm-3 control-label">密码不正确</label>
                    </c:if>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-4 col-sm-4">
                        <div class="checkbox">
                            <label>
                                <c:if test="${flag}">
                                    <input type='checkbox' name='flag' checked>请记住我</label>
                                </c:if>
                                <c:if test="${!flag}">
                                    <input type='checkbox' name='flag'>请记住我</label>
                                </c:if>
                            </label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-4 col-sm-2">
                        <button type="submit" class="btn btn-default">登录</button>
                    </div>
                    <div class=" col-sm-6">
                        <button type="submit" class="btn btn-default">注册</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="${path}/plugins/bootstrap/jquery/jquery.min.js"></script>
<script src="${path}/plugins/bootstrap/js/bootstrap.js"></script>
</body>
</html>